﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PLC.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class init : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "tb_config_data",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    DeviceConfigId = table.Column<long>(type: "bigint", nullable: false),
                    Register = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataType = table.Column<int>(type: "int", nullable: false),
                    DataLength = table.Column<int>(type: "int", nullable: false),
                    Encoding = table.Column<int>(type: "int", nullable: true),
                    CodeType = table.Column<int>(type: "int", nullable: true),
                    Status = table.Column<int>(type: "int", nullable: false),
                    DataDescription = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ConfigType = table.Column<int>(type: "int", nullable: false),
                    JudgeType = table.Column<int>(type: "int", nullable: false),
                    JudgeValue = table.Column<string>(type: "varchar(32)", maxLength: 32, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Trigger = table.Column<int>(type: "int", nullable: true),
                    CodeLength = table.Column<int>(type: "int", nullable: true),
                    OrderNum = table.Column<int>(type: "int", nullable: false, defaultValue: 0),
                    ReadGroup = table.Column<int>(type: "int", nullable: true),
                    WriteGroup = table.Column<int>(type: "int", nullable: true),
                    IsDelete = table.Column<bool>(type: "bit(1)", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    Creator = table.Column<long>(type: "bigint", nullable: false),
                    Modifier = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_config_data", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "tb_config_device",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    DeviceId = table.Column<long>(type: "bigint", nullable: false),
                    DeviceName = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Ip = table.Column<string>(type: "varchar(32)", maxLength: 32, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Port = table.Column<int>(type: "int", nullable: false),
                    MacId = table.Column<string>(type: "varchar(32)", maxLength: 32, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    HardwareType = table.Column<int>(type: "int", nullable: false),
                    PlcManufacturer = table.Column<int>(type: "int", nullable: true),
                    Protocol = table.Column<int>(type: "int", nullable: true),
                    OrderNum = table.Column<int>(type: "int", nullable: false, defaultValue: 0),
                    Status = table.Column<int>(type: "int", nullable: false),
                    DeviceType = table.Column<int>(type: "int", nullable: false),
                    IsDelete = table.Column<bool>(type: "bit(1)", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    Creator = table.Column<long>(type: "bigint", nullable: false),
                    Modifier = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_config_device", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "tb_data_airtight",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    UpperEndPlateCode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LowerEndPlateCode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Data = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    IsDelete = table.Column<bool>(type: "bit(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_data_airtight", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "tb_data_barcode",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    DeviceId = table.Column<long>(type: "bigint", nullable: false),
                    UpperEndPlateCode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LowerEndPlateCode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    MembraneElectrode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    BipolarPlate = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    IsDelete = table.Column<bool>(type: "bit(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_data_barcode", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "tb_data_ccd",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    Data = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    IsDelete = table.Column<bool>(type: "bit(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_data_ccd", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "tb_data_devicestatus",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    DeviceId = table.Column<long>(type: "bigint", nullable: false),
                    Register = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataType = table.Column<int>(type: "int", nullable: false),
                    RegisterValue = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Description = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    IsDelete = table.Column<bool>(type: "bit(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_data_devicestatus", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "tb_data_pressure",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    UpperEndPlateCode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LowerEndPlateCode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Data = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    IsDelete = table.Column<bool>(type: "bit(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_data_pressure", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "tb_data_production",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    TaskCode = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UpperEndPlateCode = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LowerEndPlateCode = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DeviceId = table.Column<long>(type: "bigint", nullable: false),
                    Result = table.Column<int>(type: "int", nullable: false),
                    Data = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    IsDelete = table.Column<bool>(type: "bit(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_data_production", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "tb_data_repairairtight",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    UpperEndPlateCode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LowerEndPlateCode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Data = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    IsDelete = table.Column<bool>(type: "bit(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_data_repairairtight", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_tb_config_data_DeviceConfigId",
                table: "tb_config_data",
                column: "DeviceConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_config_device_DeviceId",
                table: "tb_config_device",
                column: "DeviceId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_data_airtight_LowerEndPlateCode_UpperEndPlateCode",
                table: "tb_data_airtight",
                columns: new[] { "LowerEndPlateCode", "UpperEndPlateCode" });

            migrationBuilder.CreateIndex(
                name: "IX_tb_data_barcode_LowerEndPlateCode_UpperEndPlateCode",
                table: "tb_data_barcode",
                columns: new[] { "LowerEndPlateCode", "UpperEndPlateCode" });

            migrationBuilder.CreateIndex(
                name: "IX_tb_data_devicestatus_DeviceId",
                table: "tb_data_devicestatus",
                column: "DeviceId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_data_pressure_LowerEndPlateCode_UpperEndPlateCode",
                table: "tb_data_pressure",
                columns: new[] { "LowerEndPlateCode", "UpperEndPlateCode" });

            migrationBuilder.CreateIndex(
                name: "IX_tb_data_production_DeviceId",
                table: "tb_data_production",
                column: "DeviceId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_data_production_TaskCode_LowerEndPlateCode_UpperEndPlateC~",
                table: "tb_data_production",
                columns: new[] { "TaskCode", "LowerEndPlateCode", "UpperEndPlateCode" });

            migrationBuilder.CreateIndex(
                name: "IX_tb_data_repairairtight_LowerEndPlateCode_UpperEndPlateCode",
                table: "tb_data_repairairtight",
                columns: new[] { "LowerEndPlateCode", "UpperEndPlateCode" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "tb_config_data");

            migrationBuilder.DropTable(
                name: "tb_config_device");

            migrationBuilder.DropTable(
                name: "tb_data_airtight");

            migrationBuilder.DropTable(
                name: "tb_data_barcode");

            migrationBuilder.DropTable(
                name: "tb_data_ccd");

            migrationBuilder.DropTable(
                name: "tb_data_devicestatus");

            migrationBuilder.DropTable(
                name: "tb_data_pressure");

            migrationBuilder.DropTable(
                name: "tb_data_production");

            migrationBuilder.DropTable(
                name: "tb_data_repairairtight");
        }
    }
}
